package kr.hkit.powerjava.alone.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.alone.dao.BankInterfaceDao;
import kr.hkit.powerjava.alone.vo.Account;

public class AccountService extends ServiceItem<Account> {

	public AccountService(BankInterfaceDao<Account> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Account inputItemInfo(boolean gubun) {
		System.out.println("계좌번호 PW");
		Account acc = new Account(sc.nextInt(), sc.next().trim());

		if (gubun) {
			System.out.println("잔액");
			int bal = sc.nextInt();
			acc.setBalance(bal);
		}
		return acc;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1.계좌순 2.잔액순 3.번호순?");
		int res = sc.nextInt();
		switch (res) {
		case 1:
			dao.prnItemList(new Comparator<Account>() {

				@Override
				public int compare(Account o1, Account o2) {
					return o1.getAccountNo() - o2.getAccountNo();
				}
			});
			break;

		case 2:
			dao.prnItemList(new Comparator<Account>() {

				@Override
				public int compare(Account o1, Account o2) {
					return o1.getBalance() - o2.getBalance();
				}

			});
		default:
			dao.prnItemList(null);
		}

	}

}


